﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Portal/Master/Portal.Master" AutoEventWireup="true" CodeBehind="UserInfo.aspx.cs" Inherits="Besture.UI.Portal.UserCenter.UserInfo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="/Resource/css/member.css" rel="stylesheet" />
    <script type="text/javascript" src="/Admin/Themes/Js/jquery.validate.js"></script>
    <style type="text/css">
        label.error {left: 8px;top: 0;}
        .editeA {display: inherit;width: 47px;height: 27px;letter-spacing: 1px;text-align: center;background: #b10b4a;color: #fff;border-radius: 5px;font-family: 'Microsoft YaHei';font-size: 14px;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <div class="wrap">
        <div class="main member ">
            <div class="vipbanner"></div>
            <div class="container">
                <div class="layout_side">
                    <div class="side_nav">
                        <cms:UserNav runat="server" ID="UserNav" />
                    </div>
                </div>
                <div class="layout_main personinfomation">
                    <div class="vipcon">
                        <div class="viptitle1"><%=!(string.IsNullOrEmpty(LoginUserInfo.NickName))?LoginUserInfo.NickName:"" %></div>
                        <div class="grand">会员等级：<span>金牌会员</span></div>
                        <div class="pro">
                        </div>
                        <div class="pertitle">个人信息</div>
                        <div class="headimg">
                            <img src="<%=!(string.IsNullOrEmpty(LoginUserInfo.UserImage))  ? "/Upload/Image/Content/"+LoginUserInfo.UserImage :"/Resource/images/headimg.png" %>" width="115" height="120" />
                        </div>
                        <table>
                            <tr>
                                <td width="90">手机</td>
                                <td>
                                    <input type="hidden" id="hidPhone" runat="server" />
                                    <asp:TextBox ID="txtPhone" disabled="disabled" class="font_color required mobile" runat="server"></asp:TextBox>
                                </td>
                                <td width="70">
                                    <asp:Button ID="btnSavePhone" runat="server" class="themecolor edit" Text="修改" Style="width: 50px;" />
                                </td>
                            </tr>
                            <tr>
                                <td>邮箱</td>
                                <td>
                                    <input type="hidden" id="hidEmail" runat="server" />
                                    <asp:TextBox ID="txtEmail" disabled="disabled" class="font_color required email" runat="server"></asp:TextBox>
                                </td>
                                <td>
                                    <asp:Button ID="btnSaveEmail" runat="server" class="themecolor edit" Text="修改" Style="width: 50px;" />
                                </td>
                            </tr>
                            <tr>
                                <td>昵称<span class="themecolor">*</span></td>
                                <td colspan="2" class="font_color"><%=!(string.IsNullOrEmpty(LoginUserInfo.NickName))?LoginUserInfo.NickName:"未设置" %></td>
                            </tr>
                            <tr>
                                <td>姓名<span class="themecolor">*</span></td>
                                <td colspan="2" class="font_color"><%=!(string.IsNullOrEmpty(LoginUserInfo.RealName))?LoginUserInfo.RealName:"未设置" %></td>
                            </tr>
                            <tr>
                                <td>性别<span class="themecolor">*</span></td>
                                <td colspan="2" class="font_color"><%=LoginUserInfo.Sex!=0?"男":"女" %></td>
                            </tr>
                            <tr>
                                <td>生日</td>
                                <td colspan="2" class="font_color"><%=LoginUserInfo.Birthday.ToString()==""?"未设置":Convert.ToDateTime(LoginUserInfo.Birthday).ToString("yyyy-MM-dd")%></td>
                            </tr>
                            <tr>
                                <td>联系电话</td>
                                <td colspan="2" class="font_color"><%=!(string.IsNullOrEmpty(LoginUserInfo.Phone))?LoginUserInfo.Phone:"未设置" %></td>
                            </tr>
                            <tr>
                                <td>常用出发城市</td>
                                <td colspan="2" class="font_color">
                                    <label id="lblProvince" runat="server"></label>
                                </td>
                            </tr>
                            <tr>
                                <td></td>
                                <td colspan="2"><a href="UserInfoEdit.aspx" class="edite">编辑个人信息</a></td>
                            </tr>
                        </table>
                    </div>
                </div>
                <br class="clear" />
            </div>
        </div>
        <!-- //main -->
    </div>
    <!-- //wrap -->
    <script type="text/javascript">
        
        function InLoadPhoneAndEmailBotton() {
            $(".themecolor.edit").click(function () {
                $(this).parents("tr").find("input").attr("disabled", false);
                $(this).addClass("editeA");
                $(this).val("保存");
                saveEdit();
            });
        }

        function saveEdit() {
            $(".editeA").click(function () {
                //异步判断手机号是否唯一
                var vReturn = true;
                if ($("#<%=hidPhone.ClientID %>").val() !== $("#<%=txtPhone.ClientID %>").val()) {
                    $.post("/Portal/UserCenter/AjaxUserInfo.aspx", { "requestMethod": "ajax_phone", "UserType": "1", "Phone": $("#<%=txtPhone.ClientID%>").val() }, function (data) {
                        if (data > 0) {
                            alert("该手机号已被注册");
                            vReturn = false;
                        }
                    });
                }

                if ($("#<%=hidEmail.ClientID %>").val() !== $("#<%=txtEmail.ClientID %>").val()) {
                    //异步判断邮箱是否唯一
                    $.post("/Portal/UserCenter/AjaxUserInfo.aspx", { "requestMethod": "ajax_email", "UserType": "1", "Email": $("#<%=txtEmail.ClientID %>").val() }, function(data) {
                        if (data > 0) {
                            alert("该邮箱已被注册");
                            vReturn = false;
                        }
                    });
                }

                var vlabel = $(this).parents("tr").find("label");
                if (vlabel.length < 1 || vlabel.is(":hidden")) {
                    if ($(this).parents("tr").find("input:[type='text']").val().length > 0) {
                        $(this).parents("tr").find("input").attr("disabled", true);
                        $(this).removeClass("editeA");
                        $(this).val("修改"); 
                        //db 处理
                        if (vReturn) {
                            $.post("AjaxUserInfo.aspx",
                                { "requestMethod": "UserInfo", "Phone": $("#<%=txtPhone.ClientID%>").val(), "Email": $("#<%=txtEmail.ClientID%>").val() },
                                function(data) {
                                    if (data > 0) {
                                        alert("修改成功");
                                        window.location.href = "/Portal/UserCenter/UserInfo.aspx";
                                    } else {
                                        alert("修改失败");
                                        window.location.href = "/Portal/UserCenter/UserInfo.aspx";
                                    }
                                });
                        }
                        InLoadPhoneAndEmailBotton();
                    } 
                }
            });
        }


        $(function () {
            InLoadPhoneAndEmailBotton();
            //会员等级 html
            var vs = "<span style='display: inline-block; width: 400px;  height: 22px; background: #ddd; border-radius: 30px;'> "
                + " <span style='display: inline-block;width: " + $("#nightNumber").text().trim() + "%;background: #b10b4a; height: 22px;border-radius: 30px;'></span>"
                + " </span><span class='themecolor'>" + $("#SNightName").text().trim() + "</span> "
                + " （距离您成为金牌会员还有(" + (100 - $("#nightNumber").text().trim()) + ")积分&nbsp;&nbsp;&nbsp;" + $("#nightNumber").text().trim() + "/100积分)";

            $(".grand span").text($("#SNightName").text().trim());
            $(".pro").html(vs);

            $(".personinfomation table tr").each(function () {
                $(this).children("td:not(:first)").css("padding-left", "35px");
            });

            $(".edit").each(function () {
                var _this = $(this);
                _this.click(function () {
                    _this.prev().addClass("show").removeClass("none").removeAttr("readonly");
                    return false;
                });
            });
            //点击窗体其他位置关闭框
            $(window).click(function (e) {
                if (!$(e.target).parents().is("td") && !$(e.target).is(".edit")) {
                    $(".edit").prev().addClass("none");
                }
            });
            $(".date_input").date_input();
        });
    </script>
</asp:Content>
